public class CXGContactOperation{

public static void ContacttoAccountUpdate(List<Contact> ContactList){
Set<Id> ids= New Set<Id>();
ID CxGcontactRecordtypID = RecordTypeHelper.GetRecordTypeIdByDevName('Contact', 'Standard_Contact_Record_Type');     
ID CxGIOGcontactRecordtypID = RecordTypeHelper.GetRecordTypeIdByDevName('Contact', 'CSS_Contact'); 
System.Debug('ID'+CxGIOGcontactRecordtypID);
System.Debug('ID1'+CxGcontactRecordtypID);
for(Contact cont:ContactList)
{
 if(cont.RecordTypeId==CxGIOGcontactRecordtypID && cont.accountId!=null)
 {
  ids.add(cont.accountId);
 }
}
System.Debug('IDs'+ids);
List<Account> actlist=  New List<Account>();
List<Account> actlistIOG=  New List<Account>();

Account acct;
Set<Id> acctIdSet=New Set<Id>();
for(Contact cont:[Select Id,Name,accountId,Time_zone__c,MobilePhone,Fax,Email,Phone from Contact where accountid=:ids AND RecordTypeId=:CxGIOGcontactRecordtypID  AND source_type__c='CSS' order by CreatedDate desc])
{
 if(!acctIdSet.contains(cont.accountId)){
 acctIdSet.add(cont.accountId);
 acct= New Account(Id=cont.accountId);
 acct.CxG_Contact__c=cont.Id;
 acct.CxG_Contact_TimeZone__c=cont.Time_zone__c;
 acct.CxG_Mobile_number__c=cont.MobilePhone;
 acct.CxG_Contact_Phone__c=cont.Phone;
 acct.CXG_Contact_Email__c=cont.Email;
 acct.CXG_Contact_Fax__c=cont.Fax;
 actlist.add(acct);}
}
System.Debug('CSSLIST'+actlist);
try{
if(actlist.size()>0){
Update actlist;
}
}
Catch(dmlexception e)
{System.Debug(e.getMessage());
}

for(Contact cont:[Select Id,Name,accountId,Time_zone__c,MobilePhone,Fax,Email,Phone from Contact where accountid=:ids AND RecordTypeId=:CxGIOGcontactRecordtypID AND RecordTypeId!=null AND source_type__c='CXG' order by CreatedDate desc limit  1])
{
 acct= New Account(Id=cont.accountId);
 acct.CXG_Contact_Name__c=cont.Id;
 actlistIOG.add(acct);
}
System.Debug('CXGLISTSIZE'+actlistIOG.Size()+'CXGList'+actlistIOG);
try{
update actlistIOG;
}
Catch (dmlexception e){
System.debug(e);
}
}

}